package info.zlong.visibleruntime.controller;

import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mongodb.BasicDBObject;
import com.mongodb.client.MongoCollection;

import info.zlong.visibleruntime.core.mongo.MongoConnector;
import info.zlong.visibleruntime.core.util.StringUtils;

@Controller
public class IndexController  {
	@Autowired
	MongoConnector connector;
	
    @ResponseBody
    @RequestMapping(value = "/getJson")
    public Object getJson(String _id) { 
    	MongoCollection<Document> mongoCollection = connector.getMongoCollection();

    	BasicDBObject filter = new BasicDBObject();
    	if(!StringUtils.isEmpty(_id)){
    		filter.put("_id", _id.trim());
    	}
    	
    	BasicDBObject sort = new BasicDBObject();
    	sort.put("_startTime", -1);
		return mongoCollection.find(filter).sort(sort).limit(10);
    }
 
}